package com.example.teaching_server.controller;

import com.example.teaching_server.common.ApiResponse;
import com.example.teaching_server.dto.CheckInActivityDTO;
import com.example.teaching_server.service.CheckInActivityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/check-in-activities")
@RequiredArgsConstructor
@Tag(name = "打卡活动管理", description = "打卡活动相关接口")
public class CheckInActivityController {
    private final CheckInActivityService activityService;

    /**
     * 获取所有打卡卡片数据
     */
    @GetMapping
    @Operation(summary = "获取打卡活动列表", description = "获取所有打卡活动的详细信息")
    public ApiResponse<List<CheckInActivityDTO>> getAllActivities() {
        log.info("开始获取打卡活动列表");

        try {
            List<CheckInActivityDTO> dtos = activityService.getAllActivities();
            log.info("成功获取{}个打卡活动", dtos.size());
            return ApiResponse.success("打卡卡片数据获取成功", dtos);
        } catch (Exception e) {
            log.error("获取打卡卡片数据失败", e);
            return ApiResponse.fail("获取打卡卡片数据失败: " + e.getMessage());
        }
    }
}
